package sctu.edu.java.year2016.team05.xionglianjin.day20160613;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by lianjin on 2016/6/27.
 */

public class ATM {
    final JFrame a=new JFrame();
    public void ATM(){
        final String c0="123456";
        final String b0="123456";
        a.setSize(300,200);
        a.setBackground(Color.yellow);
        a.setVisible(true);
        a.setTitle("海涛系统欢迎你的登录");
        JPanel dd=new JPanel();
        a.add(dd);
        dd.setVisible(true);
        dd.setLayout(new GridLayout(3,3));
        final Label c=new Label("用户名：");
        final JTextField user=new JTextField();
        final Label d=new Label("密码：");
        final JTextField code=new JTextField();
        dd.add(c);
        dd.add(user);
        dd.add(d);
        dd.add(code);
        Button a1=new Button("确定");
        Button a2=new Button("取消");
        dd.setVisible(true);
        dd.add(a1);
        dd.add(a2);
        a.add(dd,BorderLayout.CENTER);
        // a.add(dd,BorderLayout.SOUTH);
        a1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                if(e.getActionCommand()=="确定"){
                    System.out.println("测试");
                    if(user.getText().trim().equalsIgnoreCase(c0) && code.getText().trim().equalsIgnoreCase(b0)){
                        System.out.println("right");
                        atmsystem();
                    }else{
                        JPanel cc=new JPanel();
                        JOptionPane.showMessageDialog(cc, "用户名或密码错误！", "警告", JOptionPane.WARNING_MESSAGE);
                        //System.out.println("你输入的密码或者用户名错误");
                        JFrame hh=new JFrame();
                        hh.setVisible(true);
                        //System.out.println("wrong");

                        hh.add(cc);
                        //hh.setBounds(2,2,30,20);
                        hh.setSize(300, 150);
                        hh.setLayout(new GridLayout(3,3));
                        JButton a2=new JButton("返回主页");
                        cc.add(a2);
                        cc.setLayout(new GridLayout(2,2));
                        TextField gg=new TextField("你输入的用户名或者密码有错，请重新确认之后再输入");
                        cc.add(gg);
                        cc.add(a2);
                        cc.setVisible(true);
                    }
                }else{
                    if(e.getActionCommand()=="取消")
                    {
                        System.out.println("cancer");
                        //user.remove(null);
                        user.setText("");
                        code.setText("");
                    }
                }
            }

        });
        a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public void atmsystem(){
        System.out.println("w");
    }
    public void cunkuan(){
//System.out.println("w");
    }
    public void qukuan(){

    }
    public void zhuanzhuang(){

    }
    public void grope(){

    }
    public void exit(){
        System.exit(0);
    }
    public  static  void main(String[] args){
        ATM gg=new ATM();
        gg.ATM();
    }

}